package com.movitech.mobile.cz.base.bizconfig.controller;


import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.sys.bizvo.SuppliersCategoryTemplateRequestVO;
import com.movitech.mobile.cz.base.sys.bizvo.SuppliersCategoryTemplateResponseVO;

import com.movitech.mobile.cz.base.sys.bizvo.SuppliersCategoryTemplateVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.cz.base.sys.bizvo.SuppliersCategoryTemplateListRequestVO;
import com.movitech.mobile.cz.base.bizconfig.entity.SSuppliersCategoryTemplate;
import com.movitech.mobile.cz.base.bizconfig.service.SSuppliersCategoryTemplateService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.List;

/**
 * <p>
 * SSuppliersCategoryTemplate 前端控制器
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-02-28
 */
@RestController
@RequestMapping("/v1/sSuppliersCategoryTemplate")
@Api(value = "供应商分类--模板设置基础操作接口", description = "供应商分类--模板设置基础操作接口")
public class SSuppliersCategoryTemplateController {
    @Autowired
    @Qualifier("sSuppliersCategoryTemplateService")
    private SSuppliersCategoryTemplateService sSuppliersCategoryTemplateService;

    @GetMapping("/allList")
    @ApiOperation(
            value = "获取所有供应商分类--模板设置接口",
            notes = "获取所有供应商分类--模板设置接口",
            response = SSuppliersCategoryTemplate.class
    )
    public RestReturnResult list() {
        RestReturnResult restReturnResult = RestReturnResult.success();
        Page<SSuppliersCategoryTemplate> page = sSuppliersCategoryTemplateService.selectPage(new Page<SSuppliersCategoryTemplate>());
        restReturnResult.setData(page);
        return restReturnResult;
    }

    @PostMapping("/searchList/{pageNumber}")
    @ApiOperation(
            value = "供应商分类--模板设置列表查询接口",
            notes = "供应商分类--模板设置列表查询接口",
            response = SSuppliersCategoryTemplate.class
    )
    public RestReturnResult searchList(@RequestBody SSuppliersCategoryTemplate sSuppliersCategoryTemplate,
                @ApiParam(value = "分页页数")@PathVariable Integer pageNumber) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        Page<SSuppliersCategoryTemplate> page = new Page<>();
        page.setCurrent(pageNumber);
        EntityWrapper wrapper = new EntityWrapper<>();
        wrapper.setEntity(sSuppliersCategoryTemplate);
        page = sSuppliersCategoryTemplateService.selectPage(page,wrapper);
        restReturnResult.setData(page);
        return restReturnResult;
    }

//    @GetMapping("/getSSuppliersCategoryTemplate/{id}")
//    @ApiOperation(
//            value = "供应商分类--模板设置对象ID获取接口",
//            notes = "供应商分类--模板设置对对象ID获取接口",
//            response = SSuppliersCategoryTemplate.class
//    )
//    public RestReturnResult addSSuppliersCategoryTemplate(@PathVariable String id) {
//        RestReturnResult restReturnResult = RestReturnResult.success();
//        SSuppliersCategoryTemplate sSuppliersCategoryTemplate = sSuppliersCategoryTemplateService.selectById(id);
//        restReturnResult.setData(sSuppliersCategoryTemplate);
//        return restReturnResult;
//    }

    @PostMapping("/add")
    @ApiOperation(
            value = "供应商分类--模板设置添加接口",
            notes = "供应商分类--模板设置添加接口",
            response = SSuppliersCategoryTemplate.class
    )
    public RestReturnResult add(@RequestBody SSuppliersCategoryTemplate sSuppliersCategoryTemplate) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        sSuppliersCategoryTemplateService.insert(sSuppliersCategoryTemplate);
        restReturnResult.setData(sSuppliersCategoryTemplate);
        return restReturnResult;
    }

    @PutMapping("/update")
    @ApiOperation(
            value = "供应商分类--模板设置更新接口",
            notes = "供应商分类--模板设置更新接口",
            response = SSuppliersCategoryTemplate.class
    )
    public RestReturnResult update(@RequestBody SSuppliersCategoryTemplate sSuppliersCategoryTemplate) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        sSuppliersCategoryTemplateService.updateById(sSuppliersCategoryTemplate);
        restReturnResult.setData(sSuppliersCategoryTemplate);
        return restReturnResult;
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(
            value = "供应商分类--模板设置通过ID删除接口",
            notes = "供应商分类--模板设置通过ID删除接口",
            response = SSuppliersCategoryTemplate.class
    )
    public RestReturnResult update(@PathVariable String id) {
        RestReturnResult restReturnResult = RestReturnResult.success();
        sSuppliersCategoryTemplateService.deleteById(id);
        return restReturnResult;
    }


    @PostMapping("/searchSuppliersCategoryTemplateList")
    @ApiOperation(
            value = "获取供应商分类模板接口(可分页)",
            notes = "获取供应商分类模板接口(可分页)",
            response = SSuppliersCategoryTemplate.class
    )
    public RestReturnResult searchSuppliersCategoryTemplateList(@RequestBody SuppliersCategoryTemplateListRequestVO suppliersCategoryTemplateListRequestVO) {
        RestReturnResult restReturnResult = RestReturnResult.error();

        restReturnResult = sSuppliersCategoryTemplateService.searchSuppliersCategoryTemplateList(suppliersCategoryTemplateListRequestVO);

        return restReturnResult;
    }

    @ApiOperation(
            value = "供应商分类模版新增/修改接口",
            notes = "供应商分类模版新增/修改接口",
            response = SSuppliersCategoryTemplate.class
    )
    @RequestMapping(value = "/saveOrUpdateSuppliersCategoryTemplate", method = RequestMethod.POST)
    @ResponseBody
    public RestReturnResult<Object> saveOrUpdateSuppliersCategoryTemplate(@RequestBody SuppliersCategoryTemplateVO suppliersCategoryTemplateVO){
        RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);

        try{
            hResult = sSuppliersCategoryTemplateService.saveOrUpdateSuppliersCategoryTemplate(suppliersCategoryTemplateVO);
        }catch(Exception e){
            e.printStackTrace();
            hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
        }

        return hResult;
    }

//    /**
//     * 供应商分类模版删除接口
//     * @param id
//     * @return
//     */
//    @ApiOperation(
//            value = "供应商分类模版删除接口",
//            notes = "供应商分类模版删除接口",
//            response = SSuppliersCategoryTemplate.class
//    )
//    @RequestMapping(value = "/deleteSuppliersCategoryTemplate", method = RequestMethod.GET)
//    @ResponseBody
//    public RestReturnResult<Object> deleteSuppliersCategoryTemplate(String id){
//        RestReturnResult<Object> hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[0], CommonConstants.ERROR_DESCS[0]);
//
//        try{
//            hResult = sSuppliersCategoryTemplateService.updateSuppliersCategoryTemplateForDel(id);
//        }catch(Exception e){
//            e.printStackTrace();
//            hResult = new RestReturnResult<Object>(CommonConstants.FAIL, CommonConstants.ERROR_CODES[1], CommonConstants.ERROR_DESCS[1]);
//        }
//
//        return hResult;
//    }

    @PostMapping("/getSuppliersCategoryTemplateDetails")
    @ApiOperation(
            value = "获取供应商分类模板详细接口",
            notes = "获取供应商分类模板详细接口",
            response = SSuppliersCategoryTemplate.class
    )
    public RestReturnResult getSuppliersCategoryTemplateDetails(@RequestBody SuppliersCategoryTemplateRequestVO suppliersCategoryTemplateRequestVO) {
        RestReturnResult restReturnResult = RestReturnResult.error();

        List<SuppliersCategoryTemplateResponseVO>  templateDetails = sSuppliersCategoryTemplateService.getSuppliersCategoryTemplateDetails(suppliersCategoryTemplateRequestVO);

        if(templateDetails != null){
        	restReturnResult = new RestReturnResult(CommonConstants.SUCCESS, templateDetails);
        }
        
        return restReturnResult;
    }
    
}

